package com.wxs.service.impl;

import com.wxs.mapper.TSignInMapper;
import com.wxs.po.TSignIn;
import com.wxs.po.TSignInStudent;
import com.wxs.service.TSignInStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.Calendar;


@Service
public class TSignInStudentServiceImpl implements TSignInStudentService {

    @Autowired
    TSignInMapper tSignInMapper;

    public int checkCourse(Integer courseId,Integer studentId) {
        try {
            TSignIn tSignIn = tSignInMapper.findAllCourseById(courseId);
            Calendar calendar = Calendar.getInstance();
            calendar.set(Calendar.HOUR_OF_DAY, 0);
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.SECOND, 0);
            calendar.set(Calendar.MILLISECOND, 0);
            long timeInMillis = calendar.getTimeInMillis();
            Timestamp nowTime = new Timestamp(timeInMillis);
            if (nowTime.after(tSignIn.getTime())) {
                return 1;
            }
            TSignInStudent signInStudentList = tSignInMapper.findSign(tSignIn.getId(), studentId);
            if (signInStudentList == null) {
                return 2;
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return 3;
    }

    public boolean checkSignIn(Integer signInId) {

        return false;
    }

    public int updateSignIn(Integer id) {
        return tSignInMapper.updateSignIn(id);
    }

    public int insertSignInStudent(Integer signInId, Integer studentId, Timestamp time) {
        return tSignInMapper.insertSignInStudent(signInId,studentId,time);
    }


}
